package com.wangrui.controller;


import com.wangrui.dto.MajorSchool;
import com.wangrui.utils.Page;
import com.wangrui.pojo.Major;
import com.wangrui.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王锐
 * @since 2020-07-10
 */
@Controller
@RequestMapping("/major")
public class MajorController {
    @Autowired
    private MajorService majorService;

    @RequestMapping("/majorList")
    public String majorListHtml()  {
        return "major/majorList";
    }
    @RequestMapping("/save")
    public String saveHtml()  {
        return "major/save";
    }
    @RequestMapping("/update")
    public String updateHtml()  {
        return "major/update";
    }


    @RequestMapping("/queryMajorsJson")
    @ResponseBody
    public List<Major> queryMajorsJson(){
        List<Major> list = majorService.queryMajorsJson();
        return list;
    }

    @RequestMapping("/queryAllMajors")
    public ResponseEntity<Map<String, Object>> queryAllMajors(
            @RequestParam("page")int page,
            @RequestParam("rows")int rows
    ) {
        Page<MajorSchool> page1 = new Page<>();
        page1.setPageSize(rows);
        page1.setPageIndex(page);
        Map<String, Object> stringObjectMap = majorService.AllMajors(page1);
        return ResponseEntity.ok(stringObjectMap);
    }

    @RequestMapping("/majorSave")
    public ResponseEntity<Void> majorSave(Major major)  {

        majorService.majorSave(major);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/majorUpdate")
    public ResponseEntity<Void> majorUpdate(Major major)  {
        majorService.majorUpdate(major);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/majorDelete")
    @ResponseBody
    public String majorDelete(int  ids)  {
        majorService.majorDelete(ids);
        return "ok";
    }


}

